package com.chen.Dome1create;

public class ThreadDome2_2 {
    public static void main(String[] args) {
        //目标：实现线程的创建方式二：通过实现Runnable接口(使用匿名内部类进行实现)
        //3.创建对象，调用start方法，启动线程
        Runnable mr = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println("子线程1在跑" + i);
                }

            }
        };
        //4.创建Thread对象，把Runnable接口的实现类对象作为构造参数传递
        Thread t1 = new Thread(mr);
        //5.调用start方法，启动线程
        t1.start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println("子线程2在跑" + i);
                }
            }
        }).start();
        new Thread(()-> {

                for (int i = 0; i < 5; i++) {
                    System.out.println("子线程3在跑" + i);
                }

        }).start();

        for (int i = 0; i < 5; i++) {
            System.out.println("主线程在跑" + i);
        }

    }
}
